<?php
namespace Admin\Controller;

use Common\Controller\AdminBaseController;

/**
 * 体育赛事
 */
class SportController extends AdminBaseController
{
    /**
     * 菜单列表
     */
    public function index()
    {
        $data   = D('AdminNav')->getTreeData('tree', 'order_number,id');
        $assign = array(
            'data' => $data,
        );
        $this->assign($assign);
        $this->display();
    }

    /**
     * 赛事管理
     */
    public function match()
    {
        $stype = $_GET['stype'];
        if (empty($stype)) {
            $stype = 'ft';
        }
        $data = M('sport_league')->where("stype='$stype'")->select();
        $this->assign('data', $data);
        $this->display();
    }
    public function match_add()
    {
        $data = I('post.');

        $name = M('sport_league')->where("match_name like '%" . $data['match_name'] . "%'")->getField('match_name');
        if ($name != '') {
            $this->error('不能有相同赛事名称');exit;
        }
        $result = M('sport_league')->add($data);
        if ($result) {
            $this->success('添加成功', U('Admin/Sport/match') . '/stype/' . $data['stype']);
        } else {
            $this->error('添加失败');
        }

    }
    public function match_edit()
    {
        $data = I('post.');
        $name = M('sport_league')->where("match_name like '%" . $data['match_name'] . "%' and id !=" . $data['id'])->getField('match_name');
        if ($name != '') {
            $this->error('不能有相同赛事名称');exit;
        }

        $result = M('sport_league')->save($data);

        if ($result >= 0) {
            $this->success('编辑成功', U('Admin/Sport/match') . '/stype/' . $data['stype']);
        } else {
            $this->error('编辑失败');
        }

    }

}
